﻿$(function () {
    $('.newsletter-input[type!=button]').focus(function () {
        if (this.defaultValue == $(this).val())
            $(this).val('');
    }).blur(function () {
        if ($(this).val() == '')
            $(this).val(this.defaultValue);
    });

    $('.newsletter-input[type=button]').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        NewsletterShowTooltip('czekaj...');
        $.ajax({
            type: "POST",
            url: "/Handlers/ApartsService.asmx/AddNewsletterSubscriber",
            data: "{'email': '" + $('.newsletter-input[type!=button]').val() + "','lang':'" + language.Current + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                NewsletterShowTooltip(data['d']['Message']);
            }
        });
    });
});

function NewsletterShowTooltip(message) {
    $('.newsletter-error').text(message).css('left', ($('.newsletter-input[type!=button]').position().left + 10) + 'px').show();
}
